package org.aurora.one.waitThreadEnd_3;

/**
 * @author : Aurora
 * @date : 2024/1/22 23:08
 * @description join方法测试
 */
public class MyThreadJoin {
    /**
     * 如果线程A调用了线程B的join()方法，且线程A被中断，那么将会抛出InterruptedException异常
     */
    public static void main(String[] args) throws InterruptedException {
        Thread threadOne = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("ThreadOne is Running");
                for (; ; ) ;
            }
        });
        Thread mainThread = Thread.currentThread();
        Thread threadTwo = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                mainThread.interrupt();
            }
        });
        threadOne.start();
        threadTwo.start();
        threadOne.join();
        System.out.println("Thread One is ending");
    }
}
